package com.gisocn.onemap.ui.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaScannerConnection;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.core.app.ActivityCompat;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.gisocn.onemap.base.BaseActivity;
import com.gisocn.onemap.base.Constant;
import com.gisocn.onemap.model.AppConfig;
import com.gisocn.onemap.model.AppVersion;
import com.gisocn.onemap.model.CheckDeviceModel;
import com.gisocn.onemap.model.GetPostRequest;
import com.gisocn.onemap.model.LoginModel;
import com.gisocn.onemap.model.RegisterModel;
import com.gisocn.onemap.presenter.LoginPresenter;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.utils.L;
import com.gisocn.onemap.utils.PackageUtils;
import com.gisocn.onemap.utils.SpUtils;
import com.gisocn.onemap.utils.Utils;
import com.gisocn.onemap.view.LoginView;
import com.google.gson.Gson;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

/* loaded from: classes2.dex */
public class LoginNoCheckActivity extends BaseActivity<LoginPresenter> implements LoginView {
    Intent intent;
    @BindView(R.id.login_btn)
    ImageView loginBtn;
    @BindView(R.id.login_editText_count)
    EditText loginEditTextCount;
    @BindView(R.id.login_editText_paw)
    EditText loginEditTextPaw;
    @BindView(R.id.rl_bg)
    RelativeLayout rlBg;
    boolean isregister = true;
    private String userId = "";

    @Override // com.gisocn.onemap.view.LoginView
    public void getXMLAppConfigFail(String str) {
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void getXMLAppConfigSuccess() {
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void showFailMsg(String str) {
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void updaeFinish() {
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.gisocn.onemap.base.BaseActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (getPackageName().contains("lyg")) {
            setContentView(R.layout.activity_login_lyg);
        } else {
            setContentView(R.layout.activity_login);
        }
        ButterKnife.bind(this);
        init();
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x0078, code lost:
        if (r0.equals("sg") == false) goto L3;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    void init() {
        /*
            Method dump skipped, instructions count: 294
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.gisocn.onemap.ui.activity.LoginNoCheckActivity.init():void");
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.gisocn.onemap.base.BaseActivity
    public LoginPresenter createPresenter() {
        return new LoginPresenter(this, this);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onStart() {
        super.onStart();
        initPermission();
    }

    @OnClick({R.id.login_btn})
    public void onViewClicked() {
        this.isregister = true;
        if (1 != 0) {
            showProgressDialog("登录中");
            HashMap hashMap = new HashMap();
            hashMap.put("DeviceKey", getDeviceId());
            hashMap.put("UserName", getStr(this.loginEditTextCount));
            hashMap.put("Pwd", getStr(this.loginEditTextPaw));
            ((LoginPresenter) this.presenter).getAppConfigData();
            return;
        }
        register();
    }

    void onLoginClick() {
        this.isregister = true;
        if (1 != 0) {
            showProgressDialog("登录中");
            HashMap hashMap = new HashMap();
            hashMap.put("DeviceKey", getDeviceId());
            hashMap.put("UserName", getStr(this.loginEditTextCount));
            hashMap.put("Pwd", getStr(this.loginEditTextPaw));
            ((LoginPresenter) this.presenter).getAppConfigData();
            return;
        }
        register();
    }

    void initPermission() {
        String[] strArr = {"android.permission.ACCESS_FINE_LOCATION", "android.permission.WRITE_EXTERNAL_STORAGE"};
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < 2; i++) {
            String str = strArr[i];
            if (ActivityCompat.checkSelfPermission(this, str) != 0) {
                arrayList.add(str);
            }
        }
        if (arrayList.size() > 0) {
            ActivityCompat.requestPermissions(this, (String[]) arrayList.toArray(new String[arrayList.size()]), 101);
        } else {
            onLoginClick();
        }
    }

    void getAppVersion() {
        HashMap hashMap = new HashMap();
        hashMap.put("api_token", Constant.API_TOKEN);
        hashMap.put("type", "android");
        ((LoginPresenter) this.presenter).getAppVersion(Constant.FIR_IM_VERSION_URL + getPackageName() + "?", hashMap);
    }

    @Override // androidx.fragment.app.FragmentActivity, android.app.Activity, androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        L.e("onRequestPermissionsResult" + i + "|" + strArr);
        super.onRequestPermissionsResult(i, strArr, iArr);
        if (i == 101 && iArr[0] == 0 && ActivityCompat.checkSelfPermission(this, "android.permission.WRITE_EXTERNAL_STORAGE") == 0) {
            L.e("onRequestPermissionsResult" + i + "|PERMISSION_GRANTED" + strArr);
            StringBuilder sb = new StringBuilder();
            sb.append("onRequestPermissionsResult");
            sb.append(i);
            sb.append(Constant.SAVE_PATH);
            L.e(sb.toString());
            File file = new File(Constant.SAVE_PATH);
            File file2 = new File(Constant.SAVE_PATH_TPK);
            File file3 = new File(Constant.SAVE_PATH_SHP);
            if (!file.exists()) {
                file.mkdir();
                MediaScannerConnection.scanFile(this, new String[]{file.getAbsolutePath()}, null, null);
            }
            if (!file2.exists()) {
                file2.mkdir();
                MediaScannerConnection.scanFile(this, new String[]{file2.getAbsolutePath()}, null, null);
            }
            if (file3.exists()) {
                return;
            }
            file3.mkdir();
            MediaScannerConnection.scanFile(this, new String[]{file3.getAbsolutePath()}, null, null);
        }
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void userLoginSuccess(LoginModel loginModel) {
        Log.e("userLoginSuccess", new Gson().toJson(loginModel));
        SharedPreferences.Editor edit = getSharedPreferences(getPackageName(), 0).edit();
        edit.putString("username", getStr(this.loginEditTextCount));
        edit.putString("password", getStr(this.loginEditTextPaw));
        edit.commit();
        String userId = loginModel.getData().getUserId();
        this.userId = userId;
        SpUtils.put(this, "userId", userId);
        ((LoginPresenter) this.presenter).getAppConfigData();
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void userLoginFail(String str) {
        dismissProgressDialog();
        showToast(str);
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void checkDeviceSuccess(CheckDeviceModel checkDeviceModel) {
        Log.e("checkDeviceSuccess", new Gson().toJson(checkDeviceModel));
        this.isregister = true;
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void checkDeviceFail(String str) {
        Log.e("checkDeviceFail", str);
        showToast(str);
        this.loginBtn.setImageResource(R.mipmap.icon_register);
        this.isregister = false;
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void registerDeviceSuccess(RegisterModel registerModel) {
        Log.e("registerDeviceSuccess", new Gson().toJson(registerModel));
        this.isregister = true;
        this.loginBtn.setImageResource(R.mipmap.icon_login);
        showToast("设备注册成功");
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void registerDeviceFail(String str) {
        showToast(str);
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void getAppConfig(AppConfig appConfig) {
        dismissProgressDialog();
        L.e("getAppConfig____________________");
        Intent intent = new Intent(this, MainActivity.class);
        this.intent = intent;
        intent.putExtra("appConfig", new Gson().toJson(appConfig));
        if (Constant.IS_TRIAL) {
            return;
        }
        startActivity(this.intent);
        finish();
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void getAppConfigFail(String str) {
        dismissProgressDialog();
        showToast(str);
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void getAppVersionSuccess(AppVersion appVersion) {
        if (Integer.parseInt(appVersion.getVersion()) > PackageUtils.getVersionCode(this)) {
            dismissProgressDialog();
            if (Constant.IS_TRIAL) {
                showToast("APP试用已到期,如需继续试用,请联系开发商!");
                return;
            }
            return;
        }
        startActivity(this.intent);
        finish();
    }

    @Override // com.gisocn.onemap.view.LoginView
    public void getAppVersionFail(String str) {
        showToast(str);
    }

    void register() {
        GetPostRequest.Data data = new GetPostRequest.Data();
        data.setDeviceKey(getDeviceId());
        data.setName(getStr(this.loginEditTextCount));
        data.setRemark("sfs");
        GetPostRequest getPostRequest = new GetPostRequest();
        getPostRequest.setData(data);
        ((LoginPresenter) this.presenter).registerDevice(getPostRequest);
    }

    void initSdPath() {
        L.e("Constant.SAVE_PATH_变更前" + Constant.SAVE_PATH);
        Constant.SAVE_PATH = Utils.getSdPath(this);
        if (isNull(Constant.SAVE_PATH) || Constant.SAVE_PATH.contains("null")) {
            L.e("未检测到外置SD卡");
            showToast("未检测到外置SD卡");
        }
        L.e(" Constant.SAVE_PATH_变更后" + Constant.SAVE_PATH);
    }
}
